﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Media3D;

namespace GameBoard
{
    class AdjustVisualsViewModel
    {
        private readonly ProjectionCamera _theCamera;
        List<IFlip> _flipVisuals = new List<IFlip>();
        public AdjustVisualsViewModel(ProjectionCamera theCamera)
        {
            _theCamera = theCamera;
            _theCamera.Changed += CameraChanged;

        }

        private void CameraChanged(object sender, EventArgs e)
        {
            var cld = _theCamera.LookDirection;
            cld.Normalize();
            double cameraLookZ = Math.Abs(cld.Z);
            foreach (var theVisual in _flipVisuals)
            {
                if (cameraLookZ > .7)
                {
                    theVisual.ToggleToTopDownViewMode();
                }
                else
                {
                    theVisual.ToggleToSideViewMode();
                }
            }
        }
        
        public void RegisterFlipVisual(IFlip theVisual)
        {
            _flipVisuals.Add(theVisual);
        }
        public void DeregisterFlipVisual(IFlip theVisual)
        {
            _flipVisuals.Remove(theVisual);
        }
    }
}
